package com.jiezheng.huinong.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jiezheng.huinong.dao.PaperManageDAOImpl;
import com.jiezheng.huinong.model.PaperInfo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class PaperManageAction extends ActionSupport {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 6141218847146022158L;

	private PaperInfo paper = new PaperInfo();

	private List<String> paperNos = new ArrayList<String>();

	private boolean existPaperNo = false;

	/**
	 * 增加文号
	 * 
	 * @return
	 */
	public String addPaper() {
		PaperInfo paperTest = (new PaperManageDAOImpl())
				.getPaperByPaperNo(paper.getPaperNo());
		if (paperTest != null) {
			this.setExistPaperNo(true);
			return SUCCESS;
		}

		// 增加用户部门
		Map<String, Object> session = ActionContext.getContext().getSession();
		String deptNo = (String) session.get("deptNo");
		paper.setDeptNo(deptNo);

		(new PaperManageDAOImpl()).addPaper(paper);
		return SUCCESS;
	}

	/**
	 * 删除文号
	 * 
	 * @return
	 */
	public String deletePaper() {
		(new PaperManageDAOImpl()).deletePaper(paper.getPaperNo());
		return SUCCESS;
	}

	/**
	 * 修改文号表单
	 */
	public String preModifyPaper() {
		paper = (new PaperManageDAOImpl())
				.getPaperByPaperNo(paper.getPaperNo());
		return SUCCESS;
	}

	/**
	 * 修改文号
	 * 
	 * @return
	 */
	public String modifyPaper() {
		(new PaperManageDAOImpl()).modifyPaper(paper);
		return SUCCESS;
	}

	/**
	 * 取得未被占用的文号
	 */
	public String listNoUsedIndexNo() {
		paperNos = (new PaperManageDAOImpl()).getNoUsedIndexNo();
		return SUCCESS;
	}

	/**
	 * 查询文号是否已经存在
	 * 
	 * @return
	 */

	public String listPaperExist() {
		paper = (new PaperManageDAOImpl())
				.getPaperByPaperNo(paper.getPaperNo());
		return SUCCESS;
	}

	public PaperInfo getPaper() {
		return paper;
	}

	public void setPaper(PaperInfo paper) {
		this.paper = paper;
	}

	public List<String> getPaperNos() {
		return paperNos;
	}

	public void setPaperNos(List<String> paperNos) {
		this.paperNos = paperNos;
	}

	public boolean isExistPaperNo() {
		return existPaperNo;
	}

	public void setExistPaperNo(boolean existPaperNo) {
		this.existPaperNo = existPaperNo;
	}

}
